package 递归.多路递归.杨辉三角_进一步优化空间;

public class Test {
    /**
     * 一维数组实现
     */

    public static void printSpace(int n, int i) {
        for (int j = 0; j < (n - i - 1) * 2; j++) {
            System.out.print(" ");
        }
    }

    public static void print(int n) {
        int[] row = new int[n];
        for (int i = 0; i < n; i++) {
            creatRow(row, i);
            printSpace(n, i);
            for (int j = 0; j <= i; j++) {
                System.out.printf("%-4d", row[j]);
            }
            System.out.println();
        }
    }

    private static void creatRow(int[] row, int i) {
        if (i == 0) {
            row[i] = 1;
            return;
        }
        for (int j = i; j > 0 ; j--) {
            row[j] = row[j] + row[j - 1];
        }
    }

    public static void main(String[] args) {
        print(10);
    }

}
